Redis는 오픈소스이며, key-value 저장소이다.
key를 이용해 "String", "Hash", "List", "Set", "Sorted Set"을 값으로 저장 한다.
2.6.x 기준 이야기, 2.4.x보다 빠른 성능 + 기능, 아직 정식 Release 안됨. 현재 2.6.0-rc6(2012-09-04) 2.6.0-rc8(2012-10-15)



다운로드
$ wget http://redis.googlecode.com/files/redis-2.6.0-rc6.tar.gz
$ tar xzf redis-2.4.16.tar.gz
$ cd redis-2.4.16
$ make
$ make test
실행
$ src/redis-server ./redis.conf
[6655] 27 Aug 12:32:23.522 # Unable to set the max number of files limit to 10032 (Operation not permitted), setting the max clients configuration to 3984.
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 2.5.12 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 6655
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
[6655] 27 Aug 12:32:23.522 # Server started, Redis version 2.5.12
[6655] 27 Aug 12:32:23.522 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[6655] 27 Aug 12:32:23.522 * The server is now ready to accept connections on port 6379
작동하는거야?
$ src/redis-cli
redis> set foo bar
OK
redis> get foo
"bar"
$redis-cli INCR <next_object_id>
(integer) 1
$redis-cli INCR <next_object_id>
(integer) 2
$redis-cli INCR <another_next_object_id>
(integer) 1
$redis-cli GET <next_object_id>
2
$redis-cli GET <another_next_object_id>
1
redis> SET TOTO 1
OK
redis> GET TOTO
1
redis> MULTI
OK
redis> GET TOTO
QUEUED
redis> DEL TOTO
QUEUED
redis> EXEC
1. 1
2. (integer) 1
redis> GET TOTO
(nil)
redis> select 3
OK
redis> MULTI
OK
redis> LPUSH country_list france
QUEUED
redis> LPUSH country_list italy
QUEUED
redis> LPUSH country_list germany
QUEUED
redis> INCRBY country_count 3
QUEUED
redis> LRANGE country_list 0 -1
QUEUED
redis> EXEC
1. (integer) 1
2. (integer) 2
3. (integer) 3
4. (integer) 3
5.
1. germany
2. italy
3. france
redis> LPUSH queue1 tom
(integer) 1
redis> LPUSH queue1 dick
(integer) 2
redis> LPUSH queue1 harry
(integer) 3
redis> RPOP queue1
tom
redis> RPOP queue1
dick
redis> RPOP queue1
harry
redis> SADD user:1:follows 2
(integer) 1
redis> SADD user:2:followers 1
(integer) 1
redis> SADD user:3:follows 1
(integer) 1
redis> SADD user:1:followers 3
(integer) 1
redis> SADD user:1:follows 3
(integer) 1
redis> SADD user:3:followers 1
(integer) 1
redis> SINTER user:1:follows user:1:followers
1. 3
태그 생성
SET book:1 {'title' : 'Diving into Python',
'author': 'Mark Pilgrim'}
SET book:2 { 'title' : 'Programing Erlang',
'author': 'Joe Armstrong'}
SET book:3 { 'title' : 'Programing in Haskell',
'author': 'Graham Hutton'}
SADD tag:python 1
SADD tag:erlang 2
SADD tag:haskell 3
SADD tag:programming 1 2 3
SADD tag computing 1 2 3
SADD tag:distributedcomputing 2
SADD tag:FP 2 3
태깅된 아이디 검색
a) SINTER 'tag:erlang' 'tag:haskell'
0 results
b) SINTER 'tag:programming' 'tag:computing'
3 results: 1, 2, 3
c) SUNION 'tag:erlang' 'tag:haskell'
2 results: 2 and 3
d) SDIFF 'tag:programming' 'tag:haskell'
2 results: 1 and 2 (haskell is excluded)
Connectino A
connectionA> SUBSCRIBE room:chatty
["subscribe", "room:chatty", 1]
connectionA> ...
["message", "room:chatty", "Hello there!"]
connectionA> UNSUBSCRIBE room:chatty
["unsubscribe", "room:chatty", 0]
Connection B
connectionB> PUBLISH room:chatty "Hello there!"
(integer) 1
Django + Redis + Bootstrap으로 간단한 Top10 보기 예제
^redis-django-score-example.tar.gz
Ubuntu 기준 실행
sudo apt-get install python-virtualenv
virtualenv env --no-site-packages
source env/bin/active
tar xvzf redis-django-score-example.tar.gz
cd example
pip install -r requirements.txt
python ./manage.py runserver 0.0.0.0:8000